﻿<common:UserControlBase  x:Class="ExchangeTracker.Presentation.Views.OnlineTrackItemsView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
    xmlns:common="clr-namespace:ExchangeTracker.Presentation.Common"
    xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
    xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
    xmlns:themes="http://schemas.devexpress.com/winfx/2008/xaml/grid/themekeys"
    DataContext="{Binding Source={StaticResource Locator}, Path=OnlineTrackItemsViewModel}"
    Loaded="OnlineTrackItemsView_OnLoaded"
                         x:Name="OnlineTrackUserControl"
  >
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"></RowDefinition>
            <RowDefinition Height="Auto"></RowDefinition>
            <RowDefinition Height="*"></RowDefinition>
            <RowDefinition Height="Auto"></RowDefinition>
        </Grid.RowDefinitions>
        <ToolBar Grid.Row="0">
            <Button x:Name="ExcellButton" Content="EXCEL" Click="ExcellButton_OnClick"></Button>
            <!--      <dxe:CheckEdit IsChecked="{Binding AutoRefresh}" Content="Auto Refresh"/>-->
        </ToolBar>
        <common:LayoutItem Label="گروه" Grid.Row="1">
            <dxe:ComboBoxEdit ItemsSource="{Binding SymbolGroups}" DisplayMember="Caption" Width="200" 
                        EditValue="{Binding SelectedSymbolGroup, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Left" 
                        AllowNullInput="True" ClearSelectionOnBackspace="True" PreviewKeyDown="UIElement_OnPreviewKeyDown"/>
            <!--      <ComboBox ItemsSource="{Binding SymbolGroups}" DisplayMemberPath="Caption" Width="200"-->
            <!--                        SelectedItem="{Binding SelectedSymbolGroup, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Left"-->
            <!--                        />-->
        </common:LayoutItem>
        <dxg:GridControl Grid.Row="2" Name="dataGrid" ItemsSource="{Binding TrackItems}"
                 SelectionMode="Row"
                 SelectedItem="{Binding CurrentTrackItem}"
                 dx:DXSerializer.StoreLayoutMode="All"
                 CustomUnboundColumnData="DataGrid_OnCustomUnboundColumnData"
      >
            <dxg:GridControl.Columns>
                <!--        <dxg:GridColumn FieldName="RowNumber" x:Name="RowNumber" Header="ردیف" UnboundType="Integer" Width="50" ReadOnly="True" AllowEditing="False"/>-->
                <dxg:GridColumn FieldName="CompanySymbol" x:Name="CompanySymbol" Header="نماد" Binding="{Binding Company.Symbol}" Fixed="Left"/>
                <!--        <dxg:GridColumn Header="نام" Binding="{Binding Company.Caption}"/>-->
                <dxg:GridColumn FieldName="LastTransactionPrice" x:Name="LastTransactionPrice" Header="قیمت آخرین معامله" Binding="{Binding LastTransactionPrice}" EditSettings="{dxe:TextSettings DisplayFormat=N0}"/>

                <dxg:GridColumn FieldName="FinalPrice" x:Name="FinalPrice" Header="قیمت پایانی" Binding="{Binding FinalPrice}" EditSettings="{dxe:TextSettings DisplayFormat=N0}"/>

                <!--        <dxg:GridColumn Header="اولین قیمت" Binding="{Binding FirstPrice}"/>-->
                <dxg:GridColumn FieldName="YesterdayPrice" x:Name="YesterdayPrice" Header="قیمت دیروز" Binding="{Binding YesterdayPrice}" EditSettings="{dxe:TextSettings DisplayFormat=N0}"/>

                <dxg:GridColumn FieldName="ChangeLastPercent" x:Name="ChangeLastPercent" Header="درصد آخرین معامله"
              Binding="{Binding LastTransactionPricePercent}">
                    <dxg:GridColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding RowData.Row.LastTransactionPricePercent, Mode=OneWay,StringFormat=#0.0#;(#0.0#)}" TextAlignment="Center"/>
                            <DataTemplate.Triggers>
                                <DataTrigger Binding="{Binding RowData.Row.LastTransactionPricePercent, Converter={StaticResource ValueSignToBooleanConverter}}" Value="False">
                                    <Setter Property="TextBlock.Foreground" Value="Red"/>
                                </DataTrigger>
                                <DataTrigger Binding="{Binding RowData.Row.LastTransactionPricePercent, Converter={StaticResource ValueSignToBooleanConverter}}" Value="True">
                                    <Setter Property="TextBlock.Foreground" Value="Green"/>
                                </DataTrigger>
                                <DataTrigger Binding="{Binding RowData.Row.LastTransactionPricePercent}" Value="0">
                                    <Setter Property="TextBlock.Foreground" Value="Black"/>
                                </DataTrigger>
                            </DataTemplate.Triggers>
                        </DataTemplate>

                    </dxg:GridColumn.CellTemplate>
                </dxg:GridColumn>
                <dxg:GridColumn FieldName="ChangeFinalPercent" x:Name="ChangeFinalPercent" Header="درصد پایانی"
      Binding="{Binding FinalPricePercent}">
                    <dxg:GridColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding RowData.Row.FinalPricePercent, Mode=OneWay,StringFormat=#0.0#;(#0.0#)}" TextAlignment="Center"/>
                            <DataTemplate.Triggers>
                                <DataTrigger Binding="{Binding RowData.Row.FinalPricePercent, Converter={StaticResource ValueSignToBooleanConverter}}" Value="False">
                                    <Setter Property="TextBlock.Foreground" Value="Red"/>
                                </DataTrigger>
                                <DataTrigger Binding="{Binding RowData.Row.FinalPricePercent, Converter={StaticResource ValueSignToBooleanConverter}}" Value="True">
                                    <Setter Property="TextBlock.Foreground" Value="Green"/>
                                </DataTrigger>
                                <DataTrigger Binding="{Binding RowData.Row.FinalPricePercent}" Value="0">
                                    <Setter Property="TextBlock.Foreground" Value="Black"/>
                                </DataTrigger>
                            </DataTemplate.Triggers>
                        </DataTemplate>

                    </dxg:GridColumn.CellTemplate>
                </dxg:GridColumn>

                <dxg:GridColumn FieldName="TransactionCount" x:Name="TransactionCount" Header="تعداد معاملات" Binding="{Binding TransactionCount}"/>
                <!--        <dxg:GridColumn Header="حجم معاملات" Binding="{Binding TransactionVolume}"/>-->
                <dxg:GridColumn FieldName="TransactionValue" x:Name="TransactionValue" Header="ارزش معاملات" Binding="{Binding TransactionValue}"  EditSettings="{dxe:TextSettings DisplayFormat=N0}"/>

                <!--        <dxg:GridColumn Header="ارزش بازار" Binding="{Binding MarketValue}"/>-->
                <!--        <dxg:GridColumn Header="کمترین قیمت روز" Binding="{Binding MinDayPrice}"/>-->
                <!--        <dxg:GridColumn Header="کمترین قیمت هفته" Binding="{Binding MinWeekPrice}"/>-->
                <!--        <dxg:GridColumn Header="کمترین قیمت سال" Binding="{Binding MinYearPrice}"/>-->
                <!--        <dxg:GridColumn Header="کمترین قیمت مجاز" Binding="{Binding MinValidPrice}"/>-->
                <!--        <dxg:GridColumn Header="بیشترین قیمت روز" Binding="{Binding MaxDayPrice}"/>-->
                <!--        <dxg:GridColumn Header="بیشترین قیمت هفته" Binding="{Binding MaxWeekPrice}"/>-->
                <!--        <dxg:GridColumn Header="بیشترین قیمت سال" Binding="{Binding MaxYearPrice}"/>-->
                <!--        <dxg:GridColumn Header="بیشترین قیمت مجاز" Binding="{Binding MaxValidPrice}"/>-->
                <dxg:GridColumn FieldName="StocksCount" x:Name="StocksCount" Header="تعداد سهام" Binding="{Binding StocksCount}" EditSettings="{dxe:TextSettings DisplayFormat=N0}"/>

                <dxg:GridColumn FieldName="BaseVolume" x:Name="BaseVolume" Header="حجم مبنا" Binding="{Binding BaseVolume}"  EditSettings="{dxe:TextSettings DisplayFormat=N0}"/>

                <dxg:GridColumn FieldName="FloatingStocks" x:Name="FloatingStocks" Header="ضریب شناور" Binding="{Binding FloatingStocks}" EditSettings="{dxe:TextSettings DisplayFormat=N0}"/>

                <dxg:GridColumn FieldName="MonthVolumeAvg" x:Name="MonthVolumeAvg" Header="میانگین حجم ماه" Binding="{Binding MonthVolumeAvg}"  EditSettings="{dxe:TextSettings DisplayFormat=N0}"/>
                <!--        <dxg:GridColumn Header="زمان آخرین معامله" Binding="{Binding LastTransactionTime}"/>-->
                <dxg:GridColumn FieldName="BuyRealCount" x:Name="BuyRealCount" Header="تعداد خرید PER" Binding="{Binding BuyRealCount}"
                        Style="{StaticResource BuyColumnStyle}" EditSettings="{dxe:TextSettings DisplayFormat=N0}"/>

                <dxg:GridColumn FieldName="BuyRealVolume" x:Name="BuyRealVolume" Header="حجم خرید PER" Binding="{Binding BuyRealVolume}"
                        Style="{StaticResource BuyColumnStyle}" EditSettings="{dxe:TextSettings DisplayFormat=N0}"/>

                <dxg:GridColumn FieldName="SellRealCount" x:Name="SellRealCount" Header="تعداد فروش PER" Binding="{Binding SellRealCount}"
                         Style="{StaticResource SellColumnStyle}" EditSettings="{dxe:TextSettings DisplayFormat=N0}"/>

                <dxg:GridColumn FieldName="SellRealVolume" x:Name="SellRealVolume" Header="حجم فروش PER" Binding="{Binding SellRealVolume}"
                         Style="{StaticResource SellColumnStyle}" EditSettings="{dxe:TextSettings DisplayFormat=N0}"/>

                <dxg:GridColumn FieldName="BuyLegalCount" x:Name="BuyLegalCount" Header="تعداد خرید CO" Binding="{Binding BuyLegalCount}"
                         Style="{StaticResource BuyColumnStyle}" EditSettings="{dxe:TextSettings DisplayFormat=N0}"/>

                <dxg:GridColumn FieldName="BuyLegalVolume" x:Name="BuyLegalVolume" Header="حجم خرید CO" Binding="{Binding BuyLegalVolume}"
                         Style="{StaticResource BuyColumnStyle}" EditSettings="{dxe:TextSettings DisplayFormat=N0}"/>

                <dxg:GridColumn FieldName="SellLegalCount" x:Name="SellLegalCount" Header="تعداد فروش CO" Binding="{Binding SellLegalCount}"
                         Style="{StaticResource SellColumnStyle}" EditSettings="{dxe:TextSettings DisplayFormat=N0}"/>

                <dxg:GridColumn FieldName="SellLegalVolume" x:Name="SellLegalVolume" Header="حجم فروش CO" Binding="{Binding SellLegalVolume}"
                         Style="{StaticResource SellColumnStyle}" EditSettings="{dxe:TextSettings DisplayFormat=N0}"/>

                <dxg:GridColumn FieldName="SumBuyCount" x:Name="SumBuyCount" Header="مجموع خرید" Binding="{Binding SumBuyCount}"
                         Style="{StaticResource BuyColumnStyle}" EditSettings="{dxe:TextSettings DisplayFormat=N0}"/>

                <dxg:GridColumn FieldName="SumSellCount" x:Name="SumSellCount" Header="مجموع فروش" Binding="{Binding SumSellCount}"
                         Style="{StaticResource SellColumnStyle}" EditSettings="{dxe:TextSettings DisplayFormat=N0}"/>

                <dxg:GridColumn FieldName="StatusId" x:Name="StatusId" Header="وضعیت" Binding="{Binding StatusId,Converter={StaticResource StatusConverter}}"/>
                <dxg:GridColumn FieldName="Eps" Header="EPS" Binding="{Binding Eps}" EditSettings="{dxe:TextSettings DisplayFormat=N0}"/>
                <dxg:GridColumn FieldName="Pe" Header="P/E" Binding="{Binding Pe}" EditSettings="{dxe:TextSettings DisplayFormat=N1}"/>
                <!--        <dxg:GridColumn Header="گروه P/E" Binding="{Binding GroupPe}"/>-->
                <dxg:GridColumn FieldName="RegisterDateTime" x:Name="RegisterDateTime" Header="زمان ثبت آیتم" Binding="{Binding RegisterDateTime}"/>
                <dxg:GridColumn FieldName="FormulaColumn1" x:Name="FormulaColumn1" Header="فرمول 1" Style="{StaticResource ColumnFormulaStyle}"/>
                <dxg:GridColumn FieldName="FormulaColumn2" x:Name="FormulaColumn2" Header="فرمول 2" Style="{StaticResource ColumnFormulaStyle}"/>
                <dxg:GridColumn FieldName="FormulaColumn3" x:Name="FormulaColumn3" Header="فرمول 3" Style="{StaticResource ColumnFormulaStyle}"/>
                <dxg:GridColumn FieldName="FormulaColumn4" x:Name="FormulaColumn4" Header="فرمول 4" Style="{StaticResource ColumnFormulaStyle}"/>
                <dxg:GridColumn FieldName="FormulaColumn5" x:Name="FormulaColumn5" Header="فرمول 5" Style="{StaticResource ColumnFormulaStyle}"/>
                <dxg:GridColumn FieldName="FormulaColumn6" x:Name="FormulaColumn6" Header="فرمول 6" Style="{StaticResource ColumnFormulaStyle}"/>
                <dxg:GridColumn FieldName="FormulaColumn7" x:Name="FormulaColumn7" Header="فرمول 7" Style="{StaticResource ColumnFormulaStyle}"/>
                <dxg:GridColumn FieldName="FormulaColumn8" x:Name="FormulaColumn8" Header="فرمول 8" Style="{StaticResource ColumnFormulaStyle}"/>
                <dxg:GridColumn FieldName="FormulaColumn9" x:Name="FormulaColumn9" Header="فرمول 9" Style="{StaticResource ColumnFormulaStyle}"/>
                <dxg:GridColumn FieldName="FormulaColumn10" x:Name="FormulaColumn10" Header="فرمول 10" Style="{StaticResource ColumnFormulaStyle}"/>
                <dxg:GridColumn FieldName="FormulaColumn11" x:Name="FormulaColumn11" Header="فرمول 11" Style="{StaticResource ColumnFormulaStyle}"/>

                <dxg:GridColumn FieldName="FormulaColumn12" x:Name="FormulaColumn12" Header="فرمول 12" Style="{StaticResource ColumnFormulaStyle}"/>

                <dxg:GridColumn FieldName="FormulaColumn13" x:Name="FormulaColumn13" Header="فرمول 13" Style="{StaticResource ColumnFormulaStyle}"/>

                <dxg:GridColumn FieldName="FormulaColumn14" x:Name="FormulaColumn14" Header="فرمول 14" Style="{StaticResource ColumnFormulaStyle}"/>

                <dxg:GridColumn FieldName="FormulaColumn15" x:Name="FormulaColumn15" Header="فرمول 15" Style="{StaticResource ColumnFormulaStyle}"/>

                <dxg:GridColumn FieldName="FormulaColumn16" x:Name="FormulaColumn16" Header="فرمول 16" Style="{StaticResource ColumnFormulaStyle}"/>

                <dxg:GridColumn FieldName="FormulaColumn17" x:Name="FormulaColumn17" Header="فرمول 17" Style="{StaticResource ColumnFormulaStyle}"/>

                <dxg:GridColumn FieldName="FormulaColumn18" x:Name="FormulaColumn18" Header="فرمول 18" Style="{StaticResource ColumnFormulaStyle}"/>

                <dxg:GridColumn FieldName="FormulaColumn19" x:Name="FormulaColumn19" Header="فرمول 19" Style="{StaticResource ColumnFormulaStyle}"/>

                <dxg:GridColumn FieldName="FormulaColumn20" x:Name="FormulaColumn20" Header="فرمول 20" Style="{StaticResource ColumnFormulaStyle}"/>
            </dxg:GridControl.Columns>
            <dxg:GridControl.GroupSummary>
                <dxg:GridSummaryItem SummaryType="Count" />
            </dxg:GridControl.GroupSummary>
            <dxg:GridControl.View>
                <dxg:TableView x:Name="View" ShowGroupedColumns="True" NavigationStyle="Cell" AutoWidth="False" ScrollingMode="Smart"
                       RowDoubleClick="View_OnRowDoubleClick"
                       ShowAutoFilterRow="True" FilterEditorCreated="View_OnFilterEditorCreated"
                       AllowAdvancedHorizontalNavigation="True" PreviewKeyDown="View_OnPreviewKeyDown"
                       ShowGridMenu="View_OnShowGridMenu" UseLightweightTemplates="None"
                       >
                    <!--                       ShowGridMenu="View_OnShowGridMenu"-->
                    <!--          <dxg:TableView.RuntimeLocalizationStrings>-->
                    <!--            <dxg:GridRuntimeStringCollection>-->
                    <!--              <dxg:RuntimeStringIdInfo Id="ColumnChooserCaption" Value="ستون های مخفی"/>-->
                    <!--              <dxg:RuntimeStringIdInfo Id="MenuColumnShowColumnChooser" Value="نمایش انتخاب ستون"/>-->
                    <!--              <dxg:RuntimeStringIdInfo Id="MenuColumnHideColumnChooser" Value="مخفی کردن انتخاب ستون"/>-->
                    <!--              <dxg:RuntimeStringIdInfo Id="MenuColumnFilterEditor" Value="ویرایشگر فیلتر"/>-->
                    <!--              <dxg:RuntimeStringIdInfo Id="MenuColumnShowSearchPanel" Value="جستجو"/>-->
                    <!--              <dxg:RuntimeStringIdInfo Id="MenuColumnHideSearchPanel" Value="مخفی کردن جستجو"/>-->
                    <!--            </dxg:GridRuntimeStringCollection>-->
                    <!--          </dxg:TableView.RuntimeLocalizationStrings>-->
                    <dxg:TableView.RowStyle>
                        <Style TargetType="{x:Type dxg:GridRowContent}"  BasedOn="{StaticResource {themes:GridRowThemeKey ResourceKey=RowStyle}}">
                            <Style.Triggers>
                                <Trigger Property="dxg:GridViewBase.IsFocusedRow" Value="True">
                                    <Setter Property="Background" Value="DarkOrange"/>
                                </Trigger>
                            </Style.Triggers>
                        </Style>
                    </dxg:TableView.RowStyle>
                </dxg:TableView>
            </dxg:GridControl.View>

        </dxg:GridControl>
        <!--    <dxe:ExpressionEditorControl Grid.Row="2">-->
        <!--      -->
        <!--    </dxe:ExpressionEditorControl>-->
        <!--    <dx:DXDockPanel Grid.Row="2" SnapsToDevicePixels="True">-->
        <!--      <Button Height="150" Name="ApplyFilterButton" Margin="0,4,0,8" Content="Apply Filter" dx:DXDockPanel.Dock="Bottom" HorizontalAlignment="Center" Click="ApplyFilterButtonClick" />-->
        <!--      <dxe:FilterControl x:Name="filterEditor" SourceControl="{Binding ElementName=filterGrid, Path=FilteredComponent}"-->
        <!--                     FilterCriteria="{Binding ElementName=filterGrid, Path=FilterCriteria, Mode=TwoWay}"-->
        <!--                     ShowGroupCommandsIcon="{Binding ElementName=showGroupCommandsIcon, Path=IsChecked, Mode=TwoWay}"-->
        <!--                     ShowOperandTypeIcon="{Binding ElementName=showOperandTypeIcon, Path=IsChecked, Mode=TwoWay}"-->
        <!--                     ShowToolTips="{Binding ElementName=showToolTips, Path=IsChecked, Mode=TwoWay}" />-->
        <!--    </dx:DXDockPanel>-->
    </Grid>
</common:UserControlBase >
